package io.github.uicdb.et.data.recipe;

import com.google.common.collect.Lists;
import io.github.uicdb.et.element.BasicElement;
import io.github.uicdb.et.recipe.ExtractRecipe;
import io.github.uicdb.et.recipe.ElementRecipePart;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import net.minecraft.advancements.Criterion;
import net.minecraft.core.Holder;
import net.minecraft.data.recipes.RecipeBuilder;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.neoforged.neoforge.common.crafting.ICustomIngredient;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

@RequiredArgsConstructor(staticName = "of",access = AccessLevel.PRIVATE)
public class ExtractRecipeBuilder implements RecipeBuilder {
    final Ingredient ingredient;
    final List<ElementRecipePart> result;


    public static ExtractRecipeBuilder of(TagKey<Item> tag, Holder<BasicElement> element, int amount) {
        return of(Ingredient.of(tag), Lists.newArrayList(new ElementRecipePart(element, amount)));
    }


    public static ExtractRecipeBuilder of(Ingredient ingredient, ElementRecipePart element) {
        return of(ingredient, Lists.newArrayList(element));
    }

    public static ExtractRecipeBuilder of(Item item, Holder<BasicElement> element, int amount) {
        return of(Ingredient.of(item), new ElementRecipePart(element, amount));
    }


    public static ExtractRecipeBuilder of(ItemStack itemStack, Holder<BasicElement> element, int amount) {
        return of(Ingredient.of(itemStack), new ElementRecipePart(element, amount));
    }


    public static ExtractRecipeBuilder of(ICustomIngredient customIngredient, List<ElementRecipePart> result) {
        return of(new Ingredient(customIngredient), result);
    }

    public ExtractRecipeBuilder with(Holder<BasicElement> holder, int amount) {
        result.add(new ElementRecipePart(holder, amount));
        return this;
    }

    @Override
    public @NotNull RecipeBuilder unlockedBy(String s, Criterion<?> criterion) {
        return this;
    }

    @Override
    public @NotNull RecipeBuilder group(@Nullable String s) {
        return this;
    }

    @Override
    public Item getResult() {
        return Items.AIR;
    }

    @Override
    public void save(RecipeOutput recipeOutput, @NotNull ResourceLocation resourceLocation) {
        ExtractRecipe extractRecipe = new ExtractRecipe(ingredient, result);
        recipeOutput.accept(resourceLocation, extractRecipe, null);
    }
}
